package prototipo.server.logic.transaction;

import java.util.GregorianCalendar;
import java.util.List;

import prototipo.server.logic.exception.ExceptionLogic;
import prototipo.server.logic.item.Product;
import prototipo.server.logic.item.Raw;
import prototipo.server.logic.person.Supplier;
import prototipo.server.logic.person.SupplierIF;

public class Input extends Transaction implements InputIF {

	private SupplierIF supplier;

	public Input(SupplierIF supplier, GregorianCalendar dateLatter,
			List<ItemPayIF> listItens, List<PaymentIF> payments)
			throws ExceptionLogic {
		super(dateLatter, listItens, payments);
		this.setSupplier(supplier);
	}

	/**
	 * @return the supplier
	 */
	public SupplierIF getSupplier() {
		return supplier;
	}

	/**
	 * @param supplier
	 *            the supplier to set
	 * @throws ExceptionLogic
	 */
	public void setSupplier(SupplierIF supplier) throws ExceptionLogic {
		if (supplier == null)
			throw new ExceptionLogic("Fornecedor vazio.", new Throwable(
					"Supplier is null."));
		this.supplier = supplier;
	}

	@Override
	protected boolean validateListItem(List<ItemPayIF> newListItens)
			throws ExceptionLogic {
		for (ItemPayIF itemPayIF : newListItens) {
			if (!(itemPayIF.getItem() instanceof Raw)) {
				throw new ExceptionLogic(
						"Lista de itens deve conter apenas materia prima.",
						new Throwable("ItemPay does not conten raw."));
			}
		}
		return true;
	}

}
